#include <iostream>
using std::cout;
using std::endl;

class Data{
public:
    int getData() const{
        return _data;
    }
private:
    int _data = 10;
};

class MiddleLayer{
public:
    MiddleLayer(Data * p)
    :_pdata(p)
    {

    }
    ~MiddleLayer(){
        if(_pdata){
            delete _pdata;
            _pdata = nullptr;
        }
    }
    Data * get() const{
        return _pdata;
    }

    //箭头访问运算符的重载
    //为什么这个函数一定要求以成员函数的形式进行重载？？
    //因为如果是友元，那么压根区分不了是谁的运算符
    Data * operator->(){
        return _pdata;
    }

private:
    Data * _pdata;
};
void test2(){
    MiddleLayer ml(new Data());
    //it->_word
    cout << ml->getData() << endl;
    //等价于
    cout << ml.operator->()->getData() << endl;
}

void test(){
    MiddleLayer ml(new Data());
    //此时希望调用getData函数
    cout << ml.get()->getData() << endl;
}

int main()
{
    test();
    return 0;
}

